home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Core / Includes / UAssociation.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  3.7 KB  |  129 lines  |  [TEXT/MPS ]

  1. // UAssociation.h
  2. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UASSOCIATION__
  5. #define __UASSOCIATION__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __ULIST__
  10. #include "UList.h"
  11. #endif
  12.  
  13. //----------------------------------------------------------------------------------------
  14. // Forward and external class declarations. 
  15. //----------------------------------------------------------------------------------------
  16.  
  17. class TEntry;
  18. class TEntriesList;
  19.  
  20.  
  21. //----------------------------------------------------------------------------------------
  22. // TEntry: This class associates a key CString with a value CString.
  23. //----------------------------------------------------------------------------------------
  24.  
  25. class TEntry : public TObject
  26. {
  27.     MA_DECLARE_CLASS;
  28.     
  29. public:
  30.     CStringHandle fKey;                            //  A handle to the 'keyStr'
  31.  
  32.     CStringHandle fValue;                        //  A handle to the 'valueStr'
  33.     
  34.     TEntry();
  35.         // Constructor
  36.         
  37.     void IEntry(const CStr255& itsKey, const CStr255& itsValue);
  38.         //  Initialization routine
  39.  
  40.     virtual ~TEntry();
  41.         //  Frees the fKey & fValue CString handles then calls Inherited::Free
  42.  
  43.     virtual void SetValue(const CStr255& value);
  44.         //  Sets the fValue field to theValue
  45.  
  46. };
  47.  
  48.  
  49. //----------------------------------------------------------------------------------------
  50. // TEntriesList: Subclass of TSortedList that manages a sorted list of TEntry objects,
  51. // used as an instance variable in TAssociation
  52. //----------------------------------------------------------------------------------------
  53.  
  54. class TEntriesList : public TSortedList
  55. {
  56.     MA_DECLARE_CLASS;
  57.     
  58. public:
  59.     TEntriesList();
  60.         // Empty constructor to satisfy compiler.
  61.     virtual ~TEntriesList();
  62.         // Destructor
  63.         
  64.     void IEntriesList();
  65.         // Initialize the list
  66.  
  67.     virtual CompareResult Compare(TObject* item1, TObject* item2);
  68.         // Compares 'item'1 with 'item2' returning an integer indicating the results of
  69.         // the comparison
  70.  
  71. };
  72.  
  73.  
  74. //----------------------------------------------------------------------------------------
  75. // TAssociation: This class is used to create lists of strings that are accessed via their
  76. // associated keys. The keys & strings are stored in TEntry objects which are in the
  77. // TEntriesList instance variable
  78. //----------------------------------------------------------------------------------------
  79.  
  80. class TAssociation : public TObject
  81. {
  82.     MA_DECLARE_CLASS;
  83.     
  84. public:
  85.     TEntriesList* fEntries;                        // The list of TEntries that stores the
  86.                                                 // associations
  87.                                                 
  88.  
  89.     TAssociation();
  90.         // Constructor
  91.         
  92.     void IAssociation();
  93.         // Initialization routine
  94.  
  95.     virtual ~TAssociation();
  96.         //  Frees the instance variable fEntries
  97.  
  98.     virtual Boolean ValueAt(const CStr255& keyStr, CStr255& valueStr);
  99.         // Given 'keyStr' returns the associated CString in 'valueStr', with the result
  100.         // true if an associated CString was found
  101.  
  102.     virtual Boolean KeyAt(const CStr255& valueStr, CStr255& keyStr);
  103.         // Given 'valueStr' returns the associated key in 'keyStr', with the result true
  104.         // if an associated key was found
  105.  
  106.     virtual TEntry* EntryWithKey(const CStr255& keyStr);
  107.         //  Returns the Entry containing 'keyStr'
  108.  
  109.     virtual TEntry* EntryWithValue(const CStr255& valueStr);
  110.         //  Returns the entry containing 'valueStr'
  111.  
  112.     virtual void InsertEntry(const CStr255& keyStr, const CStr255& valueStr);
  113.         // Inserts an entry into thei association, if 'keyStr' already exists then the
  114.         // value is merely replaced with 'valueStr'. Otherwise a new Entry is created with
  115.         // the above 'keyStr' and 'valueStr'
  116.  
  117.     virtual void RemoveValueAt(const CStr255& keyStr);
  118.         // Removes the value associated with 'keyStr'
  119.  
  120.     virtual void RemoveKeyAt(const CStr255& valueStr);
  121.         // Removes the key associated with 'valueStr'
  122.  
  123. };
  124.  
  125.  
  126. #endif
  127.  
  128.  
  129.